/**
 * 展示所有页面的js代码

 */
var pageNum;
var text=1;
var action=1;
var tbody=1;
$(document).ready(function() {
	loadpageNum();
	getPage();
	ajax(pageNum);
	getLastUpdate();
	getMostheat();
});

function loadpageNum(){
	pageNum=1;
}
function loadtbody(){
	tbody=1;
}

function PageNumVo(pageNum){
	this.pageNum=pageNum;
}
/*下一页  */
function next(){

	if(pageNum==2){

		alert("已到最后！！！！！！");
	}else{
		pageNum+=1;
	}

	changePage(pageNum);
}


/*上一页*/
function previous(){

	if(pageNum==1){

		pageNum=1;	

		alert("已经到了首页！！！！！");	

	}else{
		pageNum-=1;
	}

	changePage(pageNum);

}


/*改变页面的内容*/
function changePage(pageNum){

	$("#tbody").fadeOut();
	$("#tbody").empty();
	$("#tbody").fadeIn();
	ajax(pageNum);

}

/**ajax刷新页面**/
function ajax(pageNum){

	var pageNumvo1= new PageNumVo(pageNum);

	var pageNumvo=JSON.stringify(pageNumvo1);
	ajaxpost("/videomessage/getAll.do",pageNumvo,function(data){


		for(var i in data){

			var obj=data[i];
			var videoid=obj.videoid;
			var releasetime=obj.releasetime;
			var hot=obj.hot;
			var videoname=obj.videoname;
			action+="<a href="+"/videomessage/player.do?id=+"+videoid+">"+
			"<span class="+"zoom-caption"+">"+
			"<i class='icon-play fa fa-play'></i>"+
			"</span>"+
			"<img src='/images/1.jpg'/>"+
			"</a>";
			action=action.substring(1);
			text+="<div class="+"col-1-4"+">"+
			"<div class="+"wrap-col"+">"+
			"<div class="+"wrap-vid"+">"+
			"<div class="+"zoom-container"+">"+
			action+
			"</div>"+
			"<h3 class="+"vid-name"+">"+
			"<a href="+'#'+">"+videoname+"</a>"+
			"</h3>"+
			"<div class="+"info"+">"+
			"<h5>"+"admin"+"</h5>"+
			"<span>"+
			"<i class='fa fa-calendar'></i>"+
			releasetime+
			"</span>"+ 
			"<span>"+
			"<i class='fa fa-heart'></i>"+
			hot
			+"</span>"+
			"</div>"+
			"</div>"+
			"</div>"+
			"</div>";
			action=1;
			if((parseInt(i)+parseInt(1))%4==0){
				text=text.substring(1);
				text="<div class="+"row"+">"+text+"</div>";
				tbody+=text;
				text=1;    
			}

		}		
		tbody=tbody.substring(1);		
		$("#tbody").append(tbody);
		loadtbody();


	});	

}

/*获取页数*/
function getPage(){

	var params=null;
	ajaxpost("/videomessage/getPage.do", params,function(data){

		var obj=data;	

		if(obj%12==0){
			var n=obj/12;	
			for (var i = 1; i <=n ; i++) {

				var paction="<li>"+"<a href="+"javascript:changePage("+i+")>"+i+"</a>"+"</li>";          

				$("#pager").append(paction);

			}
		}else{
			var n=obj/12+1;

			for (var i = 1; i <=n ; i++) {

				var paction="<li>"+"<a href="+"javascript:changePage("+i+")>"+i+"</a>"+"</li>";          

				$("#pager").append(paction);

			}

		}


	});

}





/**单个展示页面显示最新的视频**/
function getLastUpdate(){

	var params=null;
	ajaxpost("/videomessage/getLastUpdate.do", params,function(data){
       

        for (var i in data) {
			var obj=data[i];
			var videoid=obj.videoid;
			var releasetime=obj.releasetime;
			var hot=obj.hot;
			var videoname=obj.videoname;

			var text ="<div class="+"post wrap-vid"+">"+
			"<div class="+'zoom-container'+">"+
			"<a href="+"/videomessage/player.do?id=+"+obj.videoid+">"+
			"<span class="+"zoom-caption"+">"+ 
			"<i class='icon-play fa fa-play'></i>"+
			"</span>"+
			"<img src='/images/4.jpg'/>"+
			"</a>"+
			"</div>"+
			"<div class="+"wrapper"+">"+
			"<h5 class="+"vid-name"+">"+
			"<a href="+"#"+">"+videoname+"</a>"+
			"</h5>"+
			"<div class="+"info"+">"+
			"<h6>"+
			"By"+
			"<a href="+'#'+">"+
			"Admins"+
			"</a>"+
			"</h6>"+
			"<span>"+
			"<i class="+"fa fa-calendar"+">" +
			"</i>"+releasetime+
			"</span>"+ 
			"<span>"+
			"<i class="+"fa fa-heart"+">"+
			"</i>"+hot+
			"</span>"+
			"</div>"+
			"</div>"+
			"</div>";
			
			$("#LatestPosts").append(text);
		
        }
	
		
	});
}



/**获取单个页面最火的三个视频**/
function getMostheat(){
	var params=null;
	ajaxpost("/videomessage/getMostheat.do", params,function(data){
        /**图片ajax代码不需要""拼接**/
		for (var i in data) {
			var obj=data[i];
			var videoid=obj.videoid;
			var releasetime=obj.releasetime;
			var hot=obj.hot;
			var videoname=obj.videoname;
			var text="<div class="+"row"+">"+
			"<div class="+"wrap-vid"+">"+
			"<div class="+"zoom-container"+">"+
			"<a href="+"/videomessage/player.do?id="+videoid+">"+
			"<span class="+"zoom-caption"+">"+ 
			"<i class='icon-play fa fa-play'></i>"+
			"</span>" +
			"<img src='/images/1.jpg'/>"+
			"</a>"+
			"</div>"+
			"<h3 class="+"vid-name"+">"+videoname+"</h3>"+
			"<div class="+"info"+">"+
			"<h5>"+
			"By"+ 
			"<a href="+'#'+">"+"Admins"+
			"</a>"+
			"</h5>"+	
			"<span>"+
			"<i class="+'fa fa-calendar'+">"+
			"</i>"+releasetime+
			"</span>"+ 
			"<span>"+
			"<i class="+'fa fa-heart'+">"+
			"</i>"+hot+
			"</span>"+
			"</div>"+
			"</div>"+
			"</div>";
			$("#Mostheat").append(text); 
		}	
	});


}






